/*-------------------<-- Start of Description-->---------------------\ | Create a table in the opened word document; | |---------------------<-- End of Description-->----------------------| |--------------------------------------------------------------------| |------------<-- Start of Files or Arguments Needed-->---------------| | 4 arguments are needed: | | bmark: is the name of bookmark you want to create your table | | ncols: is the number of columns you want to create your table | | width: the width of the entire table; | | colwidth: the width of the columns; | | title: T or F. | | If T, then create two rows, the first row has only one | | big cell for the title; | | if F, then create only one row, with number of columens as| | user specified. | | wordref: word reference; not necessary default is "wordsys"; | |-------------<-- End of Files or Arguments Needed-->----------------| |--------------------------------------------------------------------| |------------------<-- Start of Files Created-->---------------------| | Example: %dtable(bmark='t1', ncols=4, width=6.5); | | Usage: %dtable(bmark=,ncols=2,width=6,col1width=.,title=F, | | wordref=wordsys); | \-------------------<-- End of Files Created-->---------------------*/ %macro dtable(bmark=,ncols=2,width=6,colwidth=.,title=F,wordref=wordsys) ; /*--------------------------------------------\ | Copy Right: Duo Zhou; | | Created: 2-27-2001 11:14pm; | | Modified: 12-25-2001 2:11pm; | | Purpose: Create an empty table in the word | | document; | \--------------------------------------------*/ %local bookmark bmark ncols width colwidth title wordref _dtcnt_ hwidth _dti_ clwth; %let bookmark=%qscan(&bmark,1,%str(,()''"")); %let _dtcnt_=0; %let hwidth=&width; %if (&colwidth eq) or (&colwidth = .) %then %do; %let clwth=%sysevalf(&width/&ncols); %do _i_=1 %to &ncols; %let var&_i_=%sysevalf(&width/&ncols); %end; %end; %else %if (%quote(&colwidth) ne) and (&colwidth ne .) %then %do; %do %while(%length(%nrbquote(%scan(%nrbquote(&colwidth), %eval(&_dtcnt_+1), %nrbquote( ,()))))); %let _dtcnt_=%eval(&_dtcnt_+1); %let var&_dtcnt_=%nrbquote(%qscan(%nrbquote(&colwidth), &_dtcnt_, %nrbquote( ,()))); %if (&_dtcnt_ eq 1) %then %let clwth=&&var&_dtcnt_; %let hwidth=%sysevalf(&hwidth-&&var&_dtcnt_); %end; %if (&hwidth>0) %then %do; %if (&_dtcnt_ lt &ncols) %then %do; %do _dti_=%eval(&_dtcnt_+1) %to &ncols; %let var&_dti_=%sysevalf(&hwidth/%sysevalf(&ncols-&_dtcnt_)); %end; %end; %else %do; %put ==> Alert! Too many colwidths are given!; %goto finish; %end; %end; %else %do; %put ==> Alert! Table width less than the overall column width!; %goto finish; %end; %end; data _null_; file &wordref lrecl=2000; length str $2000.; /*put '[InsertPara]'; put '[InsertPara]'; put '[LineUp 1]'; put '[StartOfLine]';*/ %if (%quote(%upcase(&title))=F) %then %do; /*The table has 4 columns, 2 rows. Here I use format 16: single border table; .Format="28", .Format="31", .Format = "18", is all the options */; str='[TableInsertTable .ConvertFrom = "", .NumColumns = "'||trim(left(put(&ncols, 3.0)))||'", .NumRows = "1", .InitialColWidth = "Auto", .Format = "16", .Apply = "167"]'; put str; str='[TableColumnWidth .ColumnWidth = "'||trim(left(put(&var1, 4.2)))||' " + Chr$(34), .SpaceBetweenCols = "0.05" + Chr$(34), .RulerStyle = "0"]'; put str; %do _i_=2 %to &ncols; put '[CharRight 1]'; /*Push 'shift + right arrow' select the second and the third column*/ /*Set the first column to 1.18, space between columns to be 0.05*/ str=trimn(left(str))||'[TableColumnWidth .ColumnWidth = "'||trim(left(put(&&var&_i_, 4.2)))||'" + Chr$(34), .SpaceBetweenCols = "0.05" + Chr$(34), .RulerStyle = "0"]'; put str; %end; put '[StartOfRow]'; put '[StartOfColumn]'; %if (%quote(&bookmark) ne) %then %do; put '[Tableselecttable]'; put '[CharRight 1, 1]'; /*Create a bookmark*/ str='[EditBookmark .Name = "'||trim(left("&bookmark"))||'", .SortBy = 0, .Add]'; put str; put '[CharLeft 1]'; put '[Tableselecttable]'; put'[NextCell]'; %end; run; %end; %else %do; /*The table has 4 columns, 2 rows. Here I use format 16: single border table; .Format="28", .Format="31", .Format = "18", is all the options */; str='[TableInsertTable .ConvertFrom = "", .NumColumns = "'||trim(left(put(&ncols, 3.0)))||'", .NumRows = "2", .InitialColWidth = "'||trim(left(put(&clwth, 4.2)))||'" + Chr$(34), .Format = "16", .Apply = "167"]'; put str; /*Push 'shift + down arrow' select the first column*/ put '[LineDown 1, 1]'; /*Set the first column to 2.8, space between columns to be 0.05*/ str='[TableColumnWidth .ColumnWidth = "'||trim(left(put(&var1, 4.2)))||' " + Chr$(34), .SpaceBetweenCols = "0.05" + Chr$(34), .RulerStyle = "0"]'; put str; /*Move the cursor right one cell*/ %do _i_=2 %to &ncols; put '[CharRight 1]'; /*Push 'shift + down arrow' select the first column*/ put '[LineDown 1, 1]'; /*Push 'shift + right arrow' select the second and the third column*/ /*Set the first column to 1.18, space between columns to be 0.05*/ str='[TableColumnWidth .ColumnWidth = "'||trim(left(put(&&var&_i_, 4.2)))||'" + Chr$(34), .SpaceBetweenCols = "0.05" + Chr$(34), .RulerStyle = "0"]'; put str; %end; /*Push 'shift + down arrow' select the last column*/ /*Move the cursor up one cell*/ put '[NextCell]'; /*Push 'shift + left arrow' three times: select the firt row*/ %let numcells=%eval(&ncols-1); %do _j_=1 %to &numcells; put '[CharLeft 1, 1]'; %end; put '[TableMergeCells]'; /*Merge cells*/ %if (%quote(&bookmark) ne) %then %do; /*Create a bookmark*/ put '[NextCell]'; put '[EndOfRow 1]'; put '[EndOfLine 1]'; put '[EndOfColumn 1]'; put '[CharRight 1, 1]'; str='[EditBookmark .Name = "'||trim(left("&bookmark"))||'", .SortBy = 0, .Add]'; put str; put '[CharLeft 1]'; put '[Tableselecttable]'; put'[NextCell]'; %end; %end; run; %finish: %mend dtable;